
package com.yimixian.app.rest.api;

import com.yimixian.app.common.SharePreferenceKeys;
import com.yimixian.app.data.DataManager;
import com.yimixian.app.model.GoodsItem;
import com.yimixian.app.model.SearchKeyResult;
import com.yimixian.app.model.User;
import com.yimixian.app.rest.YmxDataService;
import com.yimixian.app.rest.YmxRestService;
import com.yimixian.app.rest.response.BaseResponse;
import com.yimixian.app.util.SharedPreferencesHelper;

import org.json.JSONObject;

import java.util.List;

import retrofit.Callback;
import retrofit.client.Response;

public abstract class YmxBaseAPI<T> {

    public YmxRestService mYmxRestService = YmxDataService.getInstance().getYmxRestService();
    public DataManager mDataManager = DataManager.getInstance();
    public Callback<Response> mCallback;

    /**
     * @param callback
     */
    public YmxBaseAPI(Callback<Response> callback) {
        mCallback = callback;
    }

    /**
     * api relative url
     * 
     * @return RelativeURL
     */
    public abstract String getRelativeURL();

    /**
     * parse json
     * 
     * @param jsonObject
     * @return data
     */
    public  abstract T parseJson(JSONObject jsonObject);

    public String getUserToken(){
        User user = SharedPreferencesHelper.getUser(SharePreferenceKeys.CURRENT_USER);
        if(user != null && user.token != null){
            return user.token;
        }
        return "";
    }
}
